<?php 

namespace IMT\EventBundle\Entity;

use IMT\EventBundle\Models\EventInterface;
use Doctrine\ORM\Mapping as ORM;
use BeSimple\SoapBundle\ServiceDefinition\Annotation as Soap;

/**
 * @ORM\MappedSuperclass
 */
abstract class BaseEvent implements EventInterface
{
	/**
	 * @var integer $id
	 *
	 * @ORM\Column(name="id", type="integer")
	 * @ORM\Id
	 * @ORM\GeneratedValue(strategy="AUTO")
	 * @Soap\ComplexType("int", nillable=true)
	 */
	protected $id;
	
	/**
	 * @ORM\Column(type="string", length=200)
	 * @Soap\ComplexType("string", nillable=true)
	 */
	protected $title;
	
	/**
	 * @ORM\Column(type="text")
	 * @Soap\ComplexType("string", nillable=true)
	 */
	protected $content;
	
	/**
	 * @var date $date
	 *
	 * @ORM\Column(name="date", type="datetime")
	 * @Soap\ComplexType("dateTime", nillable=true)
	 */
	protected $date;
	
	/**
	 * @var date $date
	 *
	 * @ORM\Column(name="dateFin", type="datetime")
	 * @Soap\ComplexType("dateTime", nillable=true)
	 */
	protected $dateFin;
	
	/**
	 * @var date $creaDate
	 *
	 * @ORM\Column(name="creaDate", type="datetime")
	 * @Soap\ComplexType("dateTime", nillable=true)
	 */
	protected $creaDate;
	
	/**
	 * @var date $modifDate
	 *
	 * @ORM\Column(name="modifDate", type="datetime", nullable="true")
	 * @Soap\ComplexType("dateTime", nillable=true)
	 */
	protected $modifDate;
		
	/**
	 * @ORM\Column(type="boolean")
	 * @Soap\ComplexType("boolean", nillable=true)
	 */
	protected $allDay;
	
	/**
     * @ORM\ManyToMany(targetEntity="IMT\UserBundle\Entity\User", inversedBy="events")
     */
    protected $owners;
    
    /**
	 * @ORM\ManyToMany(targetEntity="IMT\AccountBundle\Entity\Account", inversedBy="events")
	 */
	protected $accounts;
	
	
	public function __construct()
	{
		$this->date = new \DateTime;
		$this->dateFin = new \DateTime;
		$this->owners = NULL;
		$this->accounts = new \Doctrine\Common\Collections\ArrayCollection();
	}
	
		
	/**
     * {@inheritDoc}
     */
	public function setTitle($title)
	{
		$this->title = $title;
	}
	
	/**
     * {@inheritDoc}
     */
	public function getTitle()
	{
		return $this->title;
	}
	
	/**
     * {@inheritDoc}
     */
	public function setContent($content)
	{
		$this->content = $content;
	}
	
	/**
     * {@inheritDoc}
     */
	public function getContent()
	{
		return $this->content;
	}
	
	/**
     * {@inheritDoc}
     */
	public function setDate($date)
	{
		$this->date = $date;
	}
	
	/**
     * {@inheritDoc}
     */
	public function getDate()
	{
		return $this->date;
	}
	
	/**
	 * Set dateFin
	 *
	 * @param datetime $dateFin
	 */
	public function setDateFin($dateFin)
	{
		$this->dateFin = $dateFin;
	}
	
	/**
	 * Get dateFin
	 *
	 * @return datetime
	 */
	public function getDateFin()
	{
		return $this->dateFin;
	}
	
	/**
     * {@inheritDoc}
     */
	public function setCreaDate($creaDate)
	{
		$this->creaDate = $creaDate;
	}
	
	/**
     * {@inheritDoc}
     */
	public function getCreaDate()
	{
		return $this->creaDate;
	}
	
	/**
     * {@inheritDoc}
     */
	public function setModifDate($modifDate)
	{
		$this->modifDate = $modifDate;
	}
	
	/**
     * {@inheritDoc}
     */
	public function getModifDate()
	{
		return $this->modifDate;
	}
		
	/**
     * {@inheritDoc}
     */
	public function setAllDay($allDay)
	{
		$this->allDay = $allDay;
	}
	
	/**
     * {@inheritDoc}
     */
	public function getAllDay()
	{
		return $this->allDay;
	}
	
	/**
	 * Add owner
	 *
	 * @param IMT\EventBundle\Entity\BaseEvent $event
	 */
	public function addOwner(\IMT\UserBundle\Entity\User $user)
	{
		$this->owners[] = $user;
	}
	
	/**
	 * Get owners
	 *
	 * @return IMT\UserBundle\Entity\User
	 */
	public function getOwners()
	{
		return $this->owners;
	}
	
	/**
	 * add account
	 *
	 * @param IMT\AccountBundle\Entity\Account $account
	 */
	public function addAccount(\IMT\AccountBundle\Entity\Account $account)
	{
		$this->accounts[] = $account;
	}
	
	/**
	 * Set accounts
	 *
	 * @param IMT\AccountBundle\Entity\Account $account
	 */
	public function setAccounts($accounts)
	{
		$this->accounts = $accounts;
	}
	
	public function hasAccount(\IMT\AccountBundle\Entity\Account $account)
	{
		$existingAccountId = array();
		foreach($this->accounts as $value)
			$existingAccountId[] = $value->getId();
		
		return in_array($account, $existingAccountId, true);
	}
	
	/**
	 * Get accounts
	 *
	 * @return IMT\AccountBundle\Entity\Account
	 */
	public function getAccounts()
	{
		return $this->accounts;
	}
	
}